
var Nrgut_Num_Bd = new Class({
	
	Extends: Nrg_Ut_TestCase,
	
	//--------------------------------------------------------------------------
	//--------------------------------------------------------------------------
	
	testJsNativePrecision: function()
	{
		this.assertEquals( 23 * 1.4, 32.199999999999996 );
		this.assertEquals( 32.2 / 1.4, 23.000000000000004 );
		this.assertEquals( .123456789012345678901, .123456789012345678 );
		this.assertEquals(Math.pow(1.4, 8), 14.757890559999991);
	},
	
	//--------------------------------------------------------------------------
	
	testAdd: function()
	{
		this.assertEquals(
			Num.bdAdd('.555555555555555555555', '.444444444444444444444'),
			1
		);
		
		this.assertEquals(
			Num.bdAdd('.555555555555555555555', '-.444444444444444444444'),
			'.111111111111111111111'
		);
		
		this.assertEquals(
			Num.bdAdd('-.555555555555555555555', '.444444444444444444444'),
			'-.111111111111111111111'
		);
		
		this.assertEquals(
			Num.bdAdd('-.555555555555555555555', '-.444444444444444444444'),
			-1
		);
		
		this.assertEquals( Num.bdAdd(23, 1.40), 24.4 );
	},
	
	//--------------------------------------------------------------------------
	
	testSub: function()
	{
		this.assertEquals(
			Num.bdSub('.555555555555555555555', '.444444444444444444444'),
			'.111111111111111111111'
		);
		
		this.assertEquals(
			Num.bdSub('.555555555555555555555', '-.444444444444444444444'),
			1
		);
		
		this.assertEquals(
			Num.bdSub('-.555555555555555555555', '.444444444444444444444'),
			-1
		);
		
		this.assertEquals(
			Num.bdSub('-.555555555555555555555', '-.444444444444444444444'),
			'-.111111111111111111111'
		);
		
		this.assertEquals( Num.bdSub(23, 1.40), 21.6 );
	},
	
	//--------------------------------------------------------------------------
	
	testCompare: function()
	{
		this.assertEquals( Num.bdCmp(1, 2), -1 );
		this.assertEquals(
			Num.bdCmp(.1234567890, .1234567891),
			-1
		);
		this.assertEquals(
			Num.bdCmp('.12345678901234567890', '.12345678901234567891'),
			-1
		);
		
		this.assertEquals( Num.bdCmp(1, 1), 0 );
		this.assertEquals(
			Num.bdCmp(.12345678901, .12345678901),
			0
		);
		this.assertEquals(
			Num.bdCmp('.12345678901234567891', '.12345678901234567891'),
			0
		);
		
		this.assertEquals( Num.bdCmp(2, 1), 1 );
		this.assertEquals(
			Num.bdCmp(.1234567891, .1234567890),
			1
		);
		this.assertEquals(
			Num.bdCmp('.12345678901234567891', '.12345678901234567890'),
			1
		);
	},
	
	//--------------------------------------------------------------------------
	
	testCompareNegative: function()
	{
		this.assertEquals( Num.bdCmp(-1.234, 1.232), -1 );
		this.assertEquals(
			Num.bdCmp(-.1234567891, .1234567890),
			-1
		);
		this.assertEquals(
			Num.bdCmp('-.12345678901234567891', '.12345678901234567890'),
			-1
		);
		
		this.assertEquals( Num.bdCmp(-1, -1), 0 );
		this.assertEquals(
			Num.bdCmp(-.12345678901, -.12345678901),
			0
		);
		this.assertEquals(
			Num.bdCmp('-.12345678901234567891', '-.12345678901234567891'),
			0
		);
		
		this.assertEquals( Num.bdCmp(2.2345, -2.2346), 1 );
		this.assertEquals(
			Num.bdCmp(.1234567890, -.1234567892),
			1
		);
		this.assertEquals(
			Num.bdCmp('-.12345678901234567890', '-.12345678901234567891'),
			1
		);
	},
	
	//--------------------------------------------------------------------------
	
	testMul: function()
	{
		this.assertEquals( Num.bdMul(2, 2), 4 );
		this.assertEquals( Num.bdMul(2.5, 2.5), 6.25 );
		this.assertEquals( Num.bdMul(1.333, 1.333), 1.776889 );
		this.assertEquals( Num.bdMul(23, 1.40), 32.2 );
		
		this.assertEquals( Num.bdMul(-2, 2), -4 );
		this.assertEquals( Num.bdMul(-2.5, 2.5), -6.25 );
		this.assertEquals( Num.bdMul(-1.333, 1.333), -1.776889 );
		this.assertEquals( Num.bdMul(-23, 1.40), -32.2 );
		
		this.assertEquals( Num.bdMul(2, -2), -4 );
		this.assertEquals( Num.bdMul(2.5, -2.5), -6.25 );
		this.assertEquals( Num.bdMul(1.333, -1.333), -1.776889 );
		this.assertEquals( Num.bdMul(23, -1.40), -32.2 );
		
		this.assertEquals( Num.bdMul(-2, -2), 4 );
		this.assertEquals( Num.bdMul(-2.5, -2.5), 6.25 );
		this.assertEquals( Num.bdMul(-1.333, -1.333), 1.776889 );
		this.assertEquals( Num.bdMul(-23, -1.40), 32.2 );
	},
	
	//--------------------------------------------------------------------------
	
	testDiv: function()
	{
		this.assertEquals( Num.bdDiv(32.2, 1.4), 23 );
		
		this.assertEquals( Num.bdDiv(-32.2, 1.4), -23 );
		
		this.assertEquals( Num.bdDiv(32.2, -1.4), -23 );
		
		this.assertEquals( Num.bdDiv(-32.2, -1.4), 23 );
	},
	
	//--------------------------------------------------------------------------
	
	testPow: function()
	{
		this.assertEquals( Num.bdPow(10, 2), 100 );
		this.assertEquals( Num.bdPow(2, 10), 1024 );
		this.assertEquals( Num.bdPow(1.4, 8), 14.75789056 );
		this.assertEquals( Num.bdPow(-2, 10), 1024 );
		this.assertEquals( Num.bdPow(-2, 11), -2048 );
	},
	
	//--------------------------------------------------------------------------
	
	testRoundPositive: function()
	{
		this.assertEquals( Num.bdRound('.123', 2), '0.12' );
		this.assertEquals( Num.bdRound('0.125', 2), '0.13' );
		this.assertEquals( Num.bdRound('123.125', 3), '123' );
		this.assertEquals( Num.bdRound('523.125', 1), '500' );
		
		this.assertEquals(
			Num.bdRound('1234567890.1254567890123456789', 12),
			'1234567890.13'
		);
		
		this.assertEquals(
				Num.bdRound('1234567890.1234567890123456789', 12),
				'1234567890.12'
			);
		
		this.assertEquals(
			Num.bdRound('1234567890.1234567890123456789', 21),
			'1234567890.12345678901'
		);
		
		this.assertEquals(
			Num.bdRound('1234567890.1234567890163456789', 21),
			'1234567890.12345678902'
		);		
	},
	
	//--------------------------------------------------------------------------
	
	testRoundNegative: function()
	{
		this.assertEquals( Num.bdRound('-.123', 2), '-0.12' );
		this.assertEquals( Num.bdRound('-0.125', 2), '-0.13' );
		this.assertEquals( Num.bdRound('-123.125', 3), '-123' );
		this.assertEquals( Num.bdRound('-523.125', 1), '-500' );
		
		this.assertEquals(
			Num.bdRound('-1234567890.1254567890123456789', 12),
			'-1234567890.13'
		);
		
		this.assertEquals(
				Num.bdRound('-1234567890.1234567890123456789', 12),
				'-1234567890.12'
			);
		
		this.assertEquals(
			Num.bdRound('-1234567890.1234567890123456789', 21),
			'-1234567890.12345678901'
		);
		
		this.assertEquals(
			Num.bdRound('-1234567890.1234567890163456789', 21),
			'-1234567890.12345678902'
		);
	},
	
	//--------------------------------------------------------------------------
	
	testRoundLeft: function()
	{
		// FIXME: negative rounds are not implemented
		/*this.assertEquals( Num.bdRound('.123', -2), 0 );
		this.assertEquals( Num.bdRound('2.125', -2), 0 );
		this.assertEquals( Num.bdRound('1234.123', -2), 1200 );
		this.assertEquals( Num.bdRound('2.125', -2), 0 );
		this.assertEquals( Num.bdRound('-.123', -2), 0 );
		this.assertEquals( Num.bdRound('-0.125', -2), 0 );*/
	}
	
	//--------------------------------------------------------------------------

});